from five import grok
from Acquisition import aq_inner
from Products.ATContentTypes.interface.link import IATLink
from ownie.shorturl.events import IShortURLUnindexed
from zope.interface import Interface, implements, alsoProvides, providedBy, noLongerProvides
import time

class View(grok.View):
    """Render a document as a view
    """
    
    grok.context(IATLink)
    grok.require('zope2.View')
    grok.name('view.html')
    
    def update(self):
        context = aq_inner(self.context)
        self.title = context.title_or_id()
        self.description = context.Description()
        self.url = 'http://own.io/' + context.getId()#context.getRemoteUrl()
        self.indexed = not IShortURLUnindexed.providedBy(context)
        #self.preview = context.preview
        #self.message = IMessage(context)
    
#    def render(self):
#        context = aq_inner(self.context)
#        ##self.request.response.setHeader('Content-Type', 'text/csv')
#        ##self.request.response.setHeader('Content-Disposition', 'attachment; filename="%s"' % filename)#
#
#        return 'it works'
class Snippet(grok.View):
    """Render a document as a snippet
    """
    
    grok.context(IATLink)
    grok.require('zope2.View')
    grok.name('snippet.html')
    
    def update(self):
        context = aq_inner(self.context)
        self.title = context.title_or_id()
        self.description = context.Description()
        self.url = 'http://own.io/' + context.getId()#context.getRemoteUrl()
        self.indexed = not IShortURLUnindexed.providedBy(context)
